/**
 * 功能描述 行编辑
 */

define(function (require, exports, module){
	var Grid=require("grid");
	var store =require("store");
	var activeUser = store.get("user");
	var Dialog = require("dialog");
	var CheckinRoomForm = require("./checkinRoomFormComp");
	var aw = require("ajaxwrapper");
	
	var instance = {
			initComponent: function (params,widget){
				var signupgrid = new Grid({
					parentNode:".J-signupgrid",
					autoRender:false,
					model:{
						id:"signupgrid",
						allowAdd:false,
						head : {
							buttons : [ {
								id : "showRoomStatus",
								text : "查看房态",
								handler : function() {
									
									seajs.use(["eling/elcms/travel/roomstatewhole/src/roomstatewhole_main"],function(View){
										var view = new View({
														parentNode:".J-dialog-conponent",
														params:{source:"CheckInSignUp"}
													});
										Dialog.showComponent(view,{
											defaultButton:false,
											title: "房态全景",
											setStyle:function(){
												$(".modal .modal-header").hide();
												$(".modal").width(1200);
												$(".modal .J-dialog-conponent").height(600);
												$(".modal .J-dialog-conponent").css("overflow-y","auto");
											},
											buttons :[{
												id:"close",
												text:"关闭",
												handler:function(){
													Dialog.close();
												}
											}]
										});
									});
								}
							} ]
						},
						columns:[{
							name:"signUpRegister.personalInfo.idNumber",
							label:"身份证号",
						},{
							name:"signUpRegister.personalInfo.name",
							label:"姓名",
						},{
							name:"signUpRegister.personalInfo.sex.value",
							label:"性别",
						},{
							name:"signUpRegister.personalInfo.mobilePhone",
							label:"手机号",
						},{
							name:"signUpRegister.member",
							label:"是否是会员",
							format:function(value,row){
								if(row.signUpRegister.member == true){
									return "是";
								}else{
									return "否";
								}
							}
						},{
							name:"signUpRegister.travelContract.memberCertificates",
							label:"会员证号",
							format:function(value,row){
								if(row.signUpRegister.travelContract){
									return row.signUpRegister.travelContract.member.personalInfo.idNumber+
		        					"-"+row.signUpRegister.travelContract.member.personalInfo.name+
		        					"-"+row.signUpRegister.travelContract.productRule.product.name+
		        					"-"+row.signUpRegister.travelContract.memberCertificates;	
								}else{
									return "";
								}
	        				}
						},{
							name : "roomRegister.room.roomType.name",
							label : "房型"
						},{
							name : "roomRegister.room.code",
							label : "房号"
						},{
							name:"operate",
							label:"操作",
							format:"button",
							formatparams:[{
								id:"edit",
								text: "修改",
								show:function(value,data){
									if(data.signUpRegister.exitGroup == false){
										return true;
									}else{
										return false;
									}
								},
								handler:function(index,rowdata,rowEle){
									var pkDestination = widget.get("signupform").getValue("destination");
									
									aw.ajax({
										url:"api/destnbuilding/query",
										data:{
											"orgBuilding.servicePoint.pkServicePoint":activeUser.servicePoint.pkServicePoint || 1,
											"destination.pkDestination": pkDestination,
											"fetchProperties":"pkDestnBuilding," +
													"orgBuilding.name,orgBuilding.pkOrgBuilding," +
													"orgBuilding.floors,orgBuilding.roomCount,version"
										},
										dataType:"json",
										success:function(data){
											if(data.length>0){
												
												var checkinRoomForm = CheckinRoomForm.initComponent(params,widget,data);
												Dialog.showComponent(checkinRoomForm,{
													defaultButton:false,
													title: "房间设置",
													setStyle: function(){
														$(".el-dialog-modal .modal").css({
															"top": "10%",
															"width":"50%",
															"left": "25%",
														});
													},
													buttons :[{
														id:"save",
														text:"保存",
					 									className:"btn-primary",
														handler:function(){
															var pkRoom = checkinRoomForm.getValue("room");
															var roomCode = checkinRoomForm.getPlugin("room").getText();
															var pkRoomType = checkinRoomForm.getValue("roomType");
															var roomTypeName = checkinRoomForm.getPlugin("roomType").getText();
															
															rowdata.roomRegister.room={
																		pkRoom:pkRoom,
																		code:roomCode,
																		roomType:{
																			pkRoomType:pkRoomType,
																			name:roomTypeName
																		}
																	};
															signupgrid.update(index,rowdata);
															Dialog.close();
														}
													},{
														id:"close",
														text:"取消",
														handler:function(){
															Dialog.close();
														}
													}]
												});
												
											}else{
												Dialog.alert({
													content:"该目的地下没有定义楼宇"
												});
											}
										}
									});
									
								}
							}]
						}]
				}});
				widget.set("signupgrid",signupgrid);
			}
	};
	module.exports = instance;
});
